package com.example.tbag.healthcare.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.tbag.healthcare.Model.HumanInfo;
import com.example.tbag.healthcare.R;

import java.util.List;

/**
 * Created by tbag on 2017/4/21.
 */

public class HumanListAdapter extends BaseAdapter {
    private List<HumanInfo> humanInfos;
    private LayoutInflater mInflater;
    private Context context;
    
    public HumanListAdapter(List<HumanInfo> list, Context context){
        humanInfos = list;
        mInflater = LayoutInflater.from(context);
        this.context = context;
    }
    
    
    @Override
    public int getCount() {
        return humanInfos.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.layout_human_info_list, null);
            holder = new ViewHolder();
            holder.name = (TextView) convertView.findViewById(R.id.edit1);
            holder.sex = (TextView) convertView.findViewById(R.id.edit2);
            holder.age = (TextView)convertView.findViewById(R.id.edit3);
            holder.type= (TextView)convertView.findViewById(R.id.edit4);
            holder.bed =(TextView)convertView.findViewById(R.id.edit5);
            holder.bt = (TextView) convertView.findViewById(R.id.edit6); // to ItemButton
            holder.bt1 = (TextView) convertView.findViewById(R.id.edit7);
            holder.bt2 = (TextView) convertView.findViewById(R.id.edit8);
            convertView.setTag(holder); //绑定ViewHolder对象
        }
        else {
            holder = (ViewHolder) convertView.getTag(); //取出ViewHolder对象
        }
        final HumanInfo humanInfo = humanInfos.get(position);
        holder.name.setText(humanInfo.date);
        holder.sex.setText(humanInfo.time);
        holder.age.setText(humanInfo.temper);
        holder.bed.setText(humanInfo.pulse);
        holder.type.setText(humanInfo.breath);
        holder.bt.setText(humanInfo.blood);
        holder.bt1.setText(humanInfo.sugar);
        holder.bt2.setText(humanInfo.eg);
        return convertView;
    }

    public final class ViewHolder {
        public TextView name;
        public TextView sex;
        public TextView age;
        public TextView bed;
        public TextView type;
        public TextView bt;
        public TextView bt1;
        public TextView bt2;
    }
}
